<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>消息列表</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			
			.title {
				padding: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
				background-color: #fff;
			}
			
			.mui-media-body>h4 {
				font-size: 13px;
			}
			
			.mui-media-body>p {
				font-size: 11px;
			}
			
			.mui-navigate-right>span {
				background-color: red;
			}
			
			.mui-navigate-right> img {
				width: 55px;
				border-radius: 50%;
			}
		</style>
	</head>

	<body>
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--<div class="title" style="color: #2187E7;">
					消息列表
				</div>-->
				<ul id="ul" class="mui-table-view mui-table-view-chevron">
					<li id="1" class="mui-table-view-cell mui-media">
						<div class="mui-slider-right mui-disabled">
							<a class="mui-btn mui-btn-red">删除</a>
						</div>
						<a class="mui-navigate-right mui-slider-handle" id="test_im">
							<img class="mui-media-object mui-pull-left" src="../images/cbd.jpg">
							<div class="mui-media-body">
								<h4 id="name">太阳月亮 </h4>
								<p class='mui-ellipsis'>烤炉模式的城，到黄昏，如同打翻的调色盘一般.</p>
							</div>
							<span class="mui-badge mui-badge-success">22</span>
						</a>
					</li>
					<li id="2" class="mui-table-view-cell mui-media">
						<div class="mui-slider-right mui-disabled">
							<a class="mui-btn mui-btn-red">删除</a>
						</div>
						<a class="mui-navigate-right mui-slider-handle" href="javascript:openPage(this)">
							<img class="mui-media-object mui-pull-left" src="../images/cbd.jpg">
							<div class="mui-media-body">
								<h4>CBD </h4>
								<p class='mui-ellipsis'>烤炉模式的城，到黄昏，如同打翻的调色盘一般.</p>
							</div>
							<span class="mui-badge mui-badge-danger">22</span>
						</a>
					</li>
					<li id="3" class="mui-table-view-cell mui-media">
						<div class="mui-slider-right mui-disabled">
							<a class="mui-btn mui-btn-red">删除</a>
						</div>
						<a class='mui-navigate-right mui-slider-handle' href="javascript:openPage(this)">
							<img class="mui-media-object mui-pull-left" src="../images/yuantiao.jpg">
							<div class="mui-media-body">
								<h4>远眺 </h4>
								<p class='mui-ellipsis'>静静的看这个世界，最后终于疯了</p>
							</div>
							<span class="mui-badge mui-badge-danger">22</span>
						</a>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-slider-right mui-disabled">
							<a class="mui-btn mui-btn-red">删除</a>
						</div>
						<a class="mui-navigate-right mui-slider-handle" href="javascript:openPage(this)">
							<img class="mui-media-object mui-pull-left" src="../images/shuijiao.jpg">
							<div class="mui-media-body">
								<h4>幸福是什么 </h4>
								<p class='mui-ellipsis'>能和心爱的人一起睡觉，是件幸福的事情；可是，打呼噜怎么办？</p>
							</div>
							<span class="mui-badge mui-badge-danger">22</span>
						</a>
					</li>
				</ul>
			</div>
		</div>
		<script src="../libs/mui.min.js"></script>
		<script>
			mui.init({
				swipeBack: false,
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					},
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}/*,
				preloadPages: [{
					url: 'im-chat.html',
					id: 'im-chat.html',
					styles: {
						top: "44px", //新页面顶部位置
						bottom: "50px", //新页面底部位置
					},
					extras: {
						"name": document.getElementById("name").innerHTML
					}, //自定义扩展参数
				}],
				preloadLimit: 5 //预加载窗口数量限制(一旦超出,先进先出)默认不限制*/
			});
			/**
			 * 下拉刷新具体业务实现
			 */
			function pulldownRefresh() {
				setTimeout(function() {
					var table = document.body.querySelector('.mui-table-view');
					var cells = document.body.querySelectorAll('.mui-table-view-cell');
					for(var i = cells.length, len = i + 3; i < len; i++) {
						var li = document.createElement('li');
						li.id = i;
						li.className = 'mui-table-view-cell';
						li.innerHTML = '<div class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red">删除</a></div>\
						<a class="mui-navigate-right mui-slider-handle">\
							<img class="mui-media-object mui-pull-left" src="../images/shuijiao.jpg">\
							<div class="mui-media-body">\
								<h4>幸福</h4>\
								<p class="mui-ellipsis">能和心爱的人一起睡觉，是件幸福的事情；可是，打呼噜怎么办？</p>\
							</div>\
							<span class="mui-badge mui-badge-danger">' + i + '</span>\
						</a>';
						//下拉刷新，新纪录插到最前面；
						table.insertBefore(li, table.firstChild);
					}
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
				}, 1000);
			}
			var count = 0;
			/**
			 * 上拉加载具体业务实现
			 */
			function pullupRefresh() {
				setTimeout(function() {
					mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。
					var table = document.body.querySelector('.mui-table-view');
					var cells = document.body.querySelectorAll('.mui-table-view-cell');
					for(var i = cells.length, len = i + 20; i < len; i++) {
						var li = document.createElement('li');
						li.id = i;
						li.className = 'mui-table-view-cell';
						li.innerHTML = '<div class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red">删除</a></div>\
						<a class="mui-navigate-right mui-slider-handle" href="javascript:;">\
							<img class="mui-media-object mui-pull-left" src="../images/yuantiao.jpg">\
							<div class="mui-media-body">\
								<h4>远眺</h4>\
								<p class="mui-ellipsis">静静的看这个世界，最后终于疯了</p>\
							</div>\
							<span class="mui-badge mui-badge-danger">' + i + '</span>\
						</a>';
						table.appendChild(li);
					}
				}, 1000);
			}
			mui.plusReady(function() {
				//消息列表的点击事件
				mui('#ul').on('tap', 'li', function(e) {
					var value = this.querySelector('.mui-media-body h4').innerText;
					//获得主页面的webview
					//var main = plus.webview.currentWebview().parent();
					//mui.fire(main, 'gohome');					
					//main.hide();
					var newPage = plus.webview.create('im-chat.html', 'im-chat.html', {
						top: "0px",
						bottom: "0px"
					}, {
						'name': value
					});
					newPage.show();
				});
				/*
				 * 左滑删除按钮的点击事件
				 */
				mui("#ul").on('tap', '.mui-btn', function(event) {
					var btnArray = ['取消', '确认'];
					var elem = this;
					var li = elem.parentNode.parentNode;
					mui.confirm('确认删除该条记录？', '记忆', btnArray, function(e) {
						if(e.index == 1) {
							mui.toast(li.id);
							li.parentNode.removeChild(li);
						} else {
							setTimeout(function() {
								mui.swipeoutClose(li);
							}, 0);
						}
					});
				});
			});
		</script>
	</body>

</html>